<?php
/**
 * Created by PhpStorm.
 * User: jonah
 * Date: 2018/1/17
 * Time: 14:53
 */

namespace App\Admin\Extensions;

use  Encore\Admin\Form\Field;


class WangEditor extends Field
{
    protected $view = 'admin.wang-editor';

    protected static $css = [
        '/vendor/wangEditor-3.0.15/release/wangEditor.min.css',
    ];

    protected static $js = [
        '/vendor/wangEditor-3.0.15/release/wangEditor.min.js',
    ];

    public function render()
    {
        $name = $this->formatName($this->column);
        $this->script = <<<EOT

var E = window.wangEditor
var editor = new E('#{$this->id}');
editor.customConfig.menus = [
//    'indent',
    'head',  // 标题
    'bold',  // 粗体
    'italic',  // 斜体
    'underline',  // 下划线
    'strikeThrough',  // 删除线
    'foreColor',  // 文字颜色
    'backColor',  // 背景颜色
    'link',  // 插入链接
    'list',  // 列表
    'justify',  // 对齐方式
    'quote',  // 引用
    'emoticon',  // 表情
    'image',  // 插入图片
    'table',  // 表格
//    'video',  // 插入视频
    'code',  // 插入代码
    'undo',  // 撤销
    'redo'  // 重复
]
editor.customConfig.zIndex = 0
//editor.customConfig.uploadImgServer = '/uploads/'
//editor.customConfig.debug = location.href.indexOf('wangeditor_debug_mode=1') > 0
editor.customConfig.onchange = function (html) {
    $('input[name=$name]').val(html);
}
editor.create()

EOT;
        return parent::render();
    }
}